﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace TestProject.Assessment
{
    public class StubRssServiceClient
    {
        private readonly string url;
        private readonly WebClient webClient;

        public StubRssServiceClient(string url)
        {
            this.url = url + "ManagService.ashx";
            webClient = new WebClient();
        }

        public List<string> GetLogs()
        {
            var rawLog = webClient.DownloadString(url + "?op=list");
            using(var stringReader = new StringReader(rawLog))
            {
                var logs = new List<string>();
                string line;
                while ((line = stringReader.ReadLine()) != null)
                    logs.Add(line);
                return logs;
            }
        }

        public void Clear()
        {
            var result = webClient.DownloadString(url + "?op=clear");
            if(result != "0")
                throw new ApplicationException("Clear function at StubRssService failed");
        }
    }
}